﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CsQuery;
using DataLayer.Implementations;
using DonutMgmtSystemFoundation.Helpers;
using DonutMgmtSystemFoundation.Models;

namespace DonutMgmtSystemFoundation.Controllers
{
    [Authorize]
    public class DonutsController : BaseController
    {
        public ActionResult Catalog()
        {
            DonutsHelper helper = new DonutsHelper();

            return View(helper.GetActiveDonuts());
        }

        public ActionResult MyDonuts()
        {
            DonutsHelper helper = new DonutsHelper();
            ViewBag.CurrentUser = SessionContext.GetUserData();
            return View(helper.GetDonutLists());
        }

        [HttpPost]
        public JsonResult SaveMyPrefersRandom()
        {
            DonutsHelper helper = new DonutsHelper();

            return Json(helper.UpdateRandomPreferences());
        }

        [HttpPost]
        public JsonResult SaveMyDonuts(List<DonutOrderModel> donuts)
        {
            DonutsHelper helper = new DonutsHelper();

            return Json(helper.UpdatePreferences(donuts, SessionContext.GetUserData()));
        }

        public ActionResult TeamDonuts()
        {
            DonutsHelper helper = new DonutsHelper();
            
            return View(helper.GetUsersDonuts());
        }
    }
}
